
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>待结账订单</title>
	<link href="../../rs/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
	<link href="../../rs/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
	<link href="../../rs/plugins/bootstrap_tab/css/bootstrap-table.css" rel="stylesheet">
	<link href="../../rs/css/animate.min.css" rel="stylesheet">
	<link href="../../rs/css/style.min862f.css?v=4.1.0" rel="stylesheet">
	<link href="../../rs/plugins/datapicker/datepicker3.css" rel="stylesheet">
	<link href="../../rs/plugins/bootstrap-editable/css/bootstrap-editable.css" rel="stylesheet">
  <?php
    require_once('login.php');
   ?>
  <style>
         #toolbar1 {
             padding: 0px 15px;
             float: right;
         }
         .btn-group-sm > .btn, .btn-sm {
             padding: 5px 12px;
         }

         .editable-click, a.editable-click, a.editable-click:hover {
             border-bottom: 0px;
         }
         .fixed-table-pagination .page-list{
             display: none;
         }
     </style>


</head>

<body class="gray-bg">
  <div class="wrapper wrapper-content animated fadeInRight">
      <div class="ibox float-e-margins">
          <div class="ibox-content">
              
              <div class="row">
                 <div class="col-sm-4 m-b-xs">
                     
               </div>
          <div class="col-sm-4 m-b-xs"></div>
          <div class="col-sm-4 m-b-xs">
          <div id="toolbar1">
             
              <button onclick="save_do()" style="float:left;margin-left:5px" class="btn btn-success">
                  立即结账
              </button>
                <button onclick="f_sheard()" style="height:34px; margin-left:5px" type="button" class="btn btn-sm "> 刷新</button> 
          </div>
        </div>
      </div>
              <table id="table"></table>
              <!-- End Example Card View -->
          </div>
      </div>
  </div>

<script src="../../rs/js/jquery.min.js"></script>
<script src="../../rs/js/bootstrap.js"></script>
<script src="../../rs/plugins/bootstrap_tab/js/bootstrap-table.min.js"></script>
<script src="../../rs/plugins/bootstrap_tab/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="../../rs/plugins/datapicker/bootstrap-datepicker.js"></script>
<script src="../../rs/js/jquery.cookie.js"></script>
<script src="../../rs/js/common_qj.js"></script>
<script src="../../rs/plugins/layer/layer.min.js"></script>
<script src="../../rs/plugins/bootstrap-editable/js/bootstrap-editable.js"></script>
<script src="../../rs/plugins/bootstrap-editable/js/bootstrap-table-editable.min.js"></script>
<script type="text/javascript">
     var $table = $('#table');
     var sign = URLencode($.cookie('sign'));
     var  getdata;
     $(function () {
         $('#table').bootstrapTable({
					 columns: [
                           {
                             field: 'state',
                             checkbox: true
                             },
 							{
 									field: 'djbh',
 									align: 'left',
 									title: '单据编号'
 							},
                             {
 									field: 'si',
 									align: 'center', 
 									title: '应收/应付',
                                    formatter:"actionFormatter"
 							},
                              {
 									field: 'djje',
 									align: 'center', 
 									title: '单据金额'
 							},
                             {
 									field: 'ysje',
 									align: 'center',
 									title: '应收金额',
 									 editable: true
 							} ,
 							
 							{
 									field: 'yfje',
 									align: 'center',
 									title: '已付金额',
 									editable: true
 							} ,
                             {
 									field: 'bz',
 									align: 'left',
 									title: '备注',
 									editable: true,
 									 
 							}
 					],
                    singleSelect: true,
                    advancedSearch: true,
                    idTable: "advancedTable",
                    shadeClose: true,
                    toggle: "table",
            //当修改数值后执行的保存操作
             onEditableSave: function (field, row, oldValue, $el) {
                 if (field == 'yfje') {
                     if (isNaN(row.yfje)) {
                         row.yfje = oldValue;
                     }if(row.yfje==""){
						row.yfje = oldValue;
						 }else {
                      row.yfje=parseFloat(row.yfje).toFixed(2);
                     }
                 }


                  if (field == 'ysje') {
                     if (isNaN(row.yfje)) {
                         row.ysje = oldValue;
                     }if(row.ysje==""){
						row.ysje = oldValue;
						 }else {
                      row.ysje=parseFloat(row.ysje).toFixed(2);
                     }
                 }
                 
                 
                 $('#table').bootstrapTable('load', getdata); 
             }
                });
                f_sheard();
                });
 

    //获取数据
     function f_sheard() {
         
            $.ajax({
             type: "post",
             url:G_url+'filg/djs'+"?sign="+sign,
             data: 'sign=' + sign,
             dataType: "json",
             success: function (result) {
                 getdata=result.order;
                $('#table').bootstrapTable('load', result.order);
                 
             },
             error: function (XMLHttpRequest, textStatus, errorThrown) {
             }
         }); 
        
     }


   

    //保存
    function save_do(){
         var ckbh=$("#m_ck option:selected").val();
             layer.confirm('确定要结算吗？', {
                 title: [''],
                 btn: ['确定', '取消'] //按钮
             }, function (index) {
                 layer.msg('数据保存中...', {icon: 16, time: 200000, shade: [0.1, 'black']});
                 
                    var selectdata=$('#table').bootstrapTable('getSelections');
             
            
                 var djbh =selectdata[0].djbh;
                 var ysje =selectdata[0].ysje;
                 var bz =selectdata[0].bz;
                
                 $.ajax({
                     type: "post",
                     url: G_url+'filg/f_js'+"?sign="+sign,
                     data:"djbh="+djbh+"&ysje="+ysje+"&bz="+bz,
                     dataType: "json",
                     success: function(res) {
                         if (res.ok){
                              layer.msg(res.msg); 
                             f_sheard() ;
                            
                         } else {
                             layer.msg(res.msg);
                         }
                     },
                     error: function (XMLHttpRequest, textStatus, errorThrown) {
                         layer.msg('数据保存失败', {time: 1000});
                     }
                 });
                 layer.close(index);
             }, function (index) {
                 layer.close(index);
             });

     }

  function actionFormatter(value, row, index){
      if (value=="1"){
            return "<span>应收</span>";
      }else if(value=="-1"){
           return "<span>应付</span>";
      }
        
    }
    
          
 </script>
</body>
</html>
